package com.example.activity_basics;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	EditText txtMsg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button b = (Button) findViewById(R.id.btnFinish);
		txtMsg = (EditText) findViewById(R.id.txtMsg);
		Toast.makeText(this, "onCreate", 1).show();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Toast.makeText(this, "onDestroy", 1).show();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SharedPreferences myFile1 = getSharedPreferences("myFile1",
				Activity.MODE_PRIVATE);
		SharedPreferences.Editor myEditor = myFile1.edit();
		String temp = txtMsg.getText().toString();
		myEditor.putString("mydata", temp);
		myEditor.commit();
		Toast.makeText(this, "onPause", 1).show();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Toast.makeText(this, "onRestart", 1).show();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		SharedPreferences myFile = getSharedPreferences("myFile1",
				Activity.MODE_PRIVATE);
		if ((myFile != null) && (myFile.contains("mydata"))) {
			String temp = myFile.getString("mydata", "***");
			txtMsg.setText(temp);
		}
		Toast.makeText(this, "onResume", 1).show();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Toast.makeText(this, "onStart", 1).show();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Toast.makeText(this, "onStop", 1).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
